package com.lagou.order.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.lagou.entity.UserCourseOrder;
import com.lagou.order.OrderService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("order")
public class OrderController {

    @Reference
    private OrderService orderService;

    //新增订单
    @GetMapping("saveOrder/{userid}/{courseid}/{acid}/{stype}")
    public String saveOrder(@PathVariable("userid")String user_id,@PathVariable("courseid")String course_id,@PathVariable("acid")String activity_course_id,@PathVariable("stype")String source_type) {
        String orderNo = UUID.randomUUID ().toString ();
        orderService.saveOrder (orderNo,user_id,course_id,activity_course_id,source_type);
        return orderNo;
    }

    //修改订单
    @GetMapping("updateOrder/{orderno}/{status}")
    public Integer updateOrder(@PathVariable("orderno")String orderno,@PathVariable("status")Integer status) {

        Integer i = orderService.updateOrder (orderno, status);

        return i;
    }

    //删除订单
    @GetMapping("deleteOrder/{orderno}")
    public Integer deleteOrder(@PathVariable("orderno")String orderno) {

        Integer i = orderService.deleteOrder (orderno);

        return i;
    }

    //查询我的订单
    @GetMapping("getOrdersByUserId/{userId}")
    public List<UserCourseOrder> getOrdersByUserId(@PathVariable("userId")String userId) {

        List<UserCourseOrder> list = orderService.getOrdersByUserId (userId);
        return list;
    }
}
